﻿using System;
using System.Linq.Expressions;
using Medora.DataContract;
using Medora.Model.Institutions;
using Medora.Services.Utils;

namespace Medora.Services.Institutions
{
    public class ScheduleTemplateItemsService : ServiceBase<ScheduleTemplateItem, ScheduleTemplateItemFilter>, IScheduleTemplateItemsService
    {
        public ScheduleTemplateItemsService(IUow uow, IUserService userService, IFilterConstructor<ScheduleTemplateItemFilter, ScheduleTemplateItem> filterConstructor)
            : base(uow, userService, filterConstructor)
        {
            _repository = _uow.ScheduleTemplateItems;
        }

        protected override Expression<Func<ScheduleTemplateItem, bool>> ConstructFilter(Expression<Func<ScheduleTemplateItem, bool>> startE, ScheduleTemplateItemFilter filter)
        {
            if (filter == null) return startE;

            var finalE = startE;

            if (filter.ScheduleTemplateId != Guid.Empty)
            {
                Expression<Func<ScheduleTemplateItem, bool>> fExpression =
                    o => o.ScheduleTemplateId == filter.ScheduleTemplateId;
                finalE = _filterConstructor.And(finalE, fExpression);
            }
            return finalE;


        }
    }

    public interface IScheduleTemplateItemsService : IService<ScheduleTemplateItem, ScheduleTemplateItemFilter>
    {
    }
}